<?php

namespace App\Http\Controllers;

use App\Util\Tool;
use Symfony\Component\HttpFoundation\Request;

class CaptchaController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function captchaCode(Request $request)
    {
        $phone = $request->phone ?? '';
        if (empty($phone)) {
            $this->ResultJson(0, "手机号不能为空", []);
        }
        $data = Tool::CaptchaCode($phone);
        return $this->ResultJson(1, '发送成功', $data);
    }

    /**
     * 获取验证码
     * @return void
     */
    public function getCapthCode(Request $request)
    {
        $phone = $request->phone ?? '';
        if (empty($phone)) {
            return $this->ResultJson(0, "手机号不能为空", []);
        }
        $scode = Tool::GetCapthCode($phone);
        if (empty($scode)) {
            return $this->ResultJson(0, "验证码过期", []);
        }
        return $this->ResultJson(1, '图片验证码', ['scode' => $scode]);
    }
}
